package helpers;

/**
 * 
 * @author psyomn
 *
 */
public class CustomHash
{
	/**
	 * The hashing algorithm to return
	 * 16bit numbers from strings. 
	 * @param str string to be hashed
	 * @return a 16bit hash of the string
	 */
	public static int bsd_hash(String str)
	{
		int checksum = 0; 
		
		for (int i=0; i<str.length(); ++i)
		{
			checksum = 
					(checksum >> 1) + ((checksum & 1) << 15);
      
			checksum += str.charAt(i);
			checksum &= 0xffff;
		}
		
		return checksum;
	}
}
